package com.szxx.suit.missile;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.szxx.constant.DdzCardTypes;
import com.szxx.constant.DdzCardConstant;
import com.szxx.domain.Card;
import com.szxx.domain.Cards;
import com.szxx.domain.DdzCard;
import com.szxx.suit.AbstractSuitTerm;
import com.szxx.suit.AbstractSuitType;
import com.szxx.suit.DdzAnalysisResult;
import com.szxx.suit.DdzSuitAnalyzer;
import com.szxx.suit.DdzTypeUtil;
import com.szxx.util.PokerUtil;

/**
 * 火箭牌型 <br>
 *
 * @author Ambrose
 */
@Component
public class MissileTypeAnalyzer extends DdzSuitAnalyzer {

	@Override
	public AbstractSuitType getSuitType() {
		return DdzCardTypes.MISSILE;
	}

	/** 关键数量 */
	private static int TUPLE_SIZE = 2;
	
	@Override
	protected boolean doCheckRule(Cards cards, AbstractSuitTerm term, DdzAnalysisResult result) {
		if (result.getCardNum() == TUPLE_SIZE) {
			return result.getNoneLaziValueCounter().getValueCount(DdzCardConstant.BLACK_JOKER_SHAPE_NUM) == 1
					&& result.getNoneLaziValueCounter().getValueCount(DdzCardConstant.RED_JOKER_SHAPE_NUM) == 1;
		} else {
			return false;
		}
	}
	
	@Override
	protected List<Cards> doAnalysizeLaizi(Cards cards, AbstractSuitTerm term, boolean onlyMaxValue) {
		List<Cards> cardsResult = new LinkedList<Cards>();
		for (Card card : cards) {
			((DdzCard) card).changeCard(card.getNumber());
		}
		Cards cardsCopy = cards.clone();
		analysize(cardsCopy, term);
		cardsResult.add(cardsCopy);
		return cardsResult;
	}
	
	@Override
	protected void sort(Cards cards, AbstractSuitTerm term) {
		PokerUtil.sortCards_desc(cards); // 大王在前小王在后
	}
	
	@Override
	protected boolean containsPossibleCards(Cards handCards, AbstractSuitTerm term) {
		DdzAnalysisResult result = (DdzAnalysisResult) handCards.getResult();
		return result.getNoneLaziValueCounter().getValueCount(DdzCardConstant.BLACK_JOKER_SHAPE_NUM) == 1
				&& result.getNoneLaziValueCounter().getValueCount(DdzCardConstant.RED_JOKER_SHAPE_NUM) == 1;
	}
	
	@Override
	protected List<Cards> doListPossibleCards(Cards handCards, AbstractSuitTerm term) {
		List<Cards> cardsResult = new LinkedList<Cards>();
		List<Card> missileCardList = new ArrayList<Card>();
		missileCardList.addAll(DdzTypeUtil.cloneObtainedCards(handCards, DdzCardConstant.RED_JOKER_SHAPE_VALUE, 1));
		missileCardList.addAll(DdzTypeUtil.cloneObtainedCards(handCards, DdzCardConstant.BLACK_JOKER_SHAPE_VALUE, 1));
		Cards cardsCopy = DdzTypeUtil.createCardsCopy(missileCardList);
		if (match(cardsCopy, term)) {
			analysize(cardsCopy, term);
			cardsResult.add(cardsCopy);
		}
		return cardsResult;
	}

}
